<include file="public@header" />
<style type="text/css">
    .pic-list li {
        margin-bottom: 5px;
    }
</style>
<script type="text/html" id="photos-item-tpl">
    <li id="saved-image{id}">
        <input id="photo-{id}" type="hidden" name="photo_urls[]" value="{filepath}">
        <input class="form-control" id="photo-{id}-name" type="text" name="photo_names[]" value="{name}"
            style="width: 200px;" title="图片名称">
        <img id="photo-{id}-preview" src="{url}" style="height:36px;width: 36px;"
            onclick="imagePreviewDialog(this.src);">
        <a href="javascript:uploadOneImage('图片上传','#photo-{id}');">替换</a>
        <a href="javascript:(function(){$('#saved-image{id}').remove();})();">移除</a>
    </li>
</script>
<script type="text/html" id="files-item-tpl">
    <li id="saved-file{id}">
        <input id="file-{id}" type="hidden" name="file_urls[]" value="{filepath}">
        <input class="form-control" id="file-{id}-name" type="text" name="file_names[]" value="{name}"
            style="width: 200px;" title="文件名称">
        <a id="file-{id}-preview" href="{preview_url}" target="_blank">下载</a>
        <a href="javascript:uploadOne('文件上传','#file-{id}','file');">替换</a>
        <a href="javascript:(function(){$('#saved-file{id}').remove();})();">移除</a>
    </li>
</script>
</head>

<body>
    <div class="wrap js-check-wrap">
        <form action="{:url()}?post_id={:request()->param('post_id')}&layer={:request()->param('layer')}" method="post"
            class="form-horizontal js-ajax-form margin-top-20">
            <div class="row">
                <div class="col-md-9">
                    <table class="table table-bordered">
                        <tr>
                            <th width="100">注意事项<span class="form-required">*</span></th>
                            <td>
                                必填字段是: 选择分类（勾选项目名即可）、标题、简介、内容、和缩略图（右上角），其它字段暂未开发.&nbsp;&nbsp;&nbsp;
                                视频上传限制10M，大于10M的视频请使用视频链接.
                            </td>
                        </tr>
                        <tr>
                            <th>标题<span class="form-required">*</span></th>
                            <td>
                                <input class="form-control" type="text" name="title" id="title" required value=""
                                    placeholder="请输入标题" />
                            </td>
                        </tr>
                        <tr>
                            <th>关键词</th>
                            <td>
                                <input class="form-control" type="text" name="keywords" id="keywords" value=""
                                    placeholder="请输入关键字">
                                <p class="help-block">多关键词之间用英文逗号隔开</p>
                            </td>
                        </tr>
                        <tr>
                            <th>文章来源</th>
                            <td><input class="form-control" type="text" name="source" id="source" value=""
                                    placeholder="请输入文章来源"></td>
                        </tr>
                        <tr>
                            <th>简介</th>
                            <td>
                                <textarea class="form-control" name="description" style="height: 50px;"
                                    placeholder="请填写简介"></textarea>
                            </td>
                        </tr>
                        <tr>
                            <th>附件</th>
                            <td>
                                <div style="display: flex">
                                    <input type="text" class="form-control" id='appendix' name="appendix">
                                    <input type="file" id='sendFile' style="display: none;">
                                    <button type="button" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th><b>封面图</b></th>
                            <td>
                                <div style="text-align: center;">
                                    <input type="hidden" name="pic" id="thumbnail" value="">
                                    <a href="javascript:uploadOneImage('图片上传','#thumbnail');">
                                        <img src="__TMPL__/public/assets/images/default-thumbnail.png"
                                            id="thumbnail-preview" width="135" style="cursor: pointer" />
                                    </a>
                                    <input type="button" class="btn btn-sm btn-cancel-thumbnail" value="取消图片">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th>视频</th>
                            <td class="form-inline">
                                <input id="file-video" class="form-control" type="text" name="video"
                                    value="{$post.more.video|default=''}" placeholder="请上传视频文件" style="width: 200px;">
                                <notempty name="post.more.video">
                                    <a id="file-video-preview" href="{:cmf_get_file_download_url($post.more.video)}"
                                        target="_blank">下载</a>
                                </notempty>
                                <a href="javascript:uploadOne('文件上传','#file-video','video');">上传</a>
                            </td>
                        </tr>
                    </table>
                    <hook name="portal_admin_article_edit_view_main" />
                    <div class="form-group">
                        <div class="col-sm-offset-2 col-sm-10">
                            <button type="submit" class="btn btn-primary js-ajax-submit-iframe">{:lang('ADD')}</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript" src="__STATIC__/js/admin.js"></script>
    <!--
    <script type="text/javascript">
        //编辑器路径定义
        var editorURL = GV.WEB_ROOT;
        console.log(editorURL)
    </script>
    <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.config.js"></script>
    <script type="text/javascript" src="__STATIC__/js/ueditor/ueditor.all.min.js"></script>
    -->
    <script src="__STATIC__/layer/layer.js"></script>
    <script type="text/javascript">
        $(function () {
            // editorcontent = new baidu.editor.ui.Editor();
            // editorcontent.render('content');
            // try {
            //     editorcontent.sync();
            // } catch (err) { }
            // $('.btn-cancel-thumbnail').click(function () {
            //     $('#thumbnail-preview').attr('src',
            //         '__TMPL__/public/assets/images/default-thumbnail.png');
            //     $('#thumbnail').val('');
            // });


            $('.js-ajax-submit').on('click', function () {
                $("#sendFile").click();
            })
            $("#sendFile").on('change', function () {

                var files = this.files[0];
                var thar = this;
                var formData = new FormData();
                formData.append('file', files);
                formData.append('app', 'portal');
                formData.append('filetype', 'file');
                formData.append('name', files.name);
                formData.append('type', files.type);
                formData.append('lastModifiedDate', new Date());
                formData.append('size', files.size);
                formData.append('WU_FILE_0', 123);

                $.ajax({
                    url: '/user/asset/webuploader.html?_ajax=1',
                    type: "POST",
                    data: formData,
                    processData: false,
                    contentType: false,
                    success: function (res) {
                        if (res.code === 1) {
                            $('#appendix').val(res.data.url)
                        }
                        layer.msg(res.msg)
                        $(thar).val('');
                    }
                })
            })
        });
    </script>
</body>

</html>